-- HEIST TOOL SKIDDED FROM DECOMPILED SCRIPTS AND EVERYONE IN EXISTENCE
-- 抢劫工具 - 源自反编译脚本和所有人的贡献

local function generate_list(min, max, step)
    local list = {}
    for i = min, max, step do
        table.insert(list, {tostring(i), i})
    end
    return list
end

local function generate_list_percent(min, max, step)
    local list = {}
    for i = min, max, step do
        table.insert(list, {i .. '%', i})
    end
    return list
end

local function find_index(list, value)
    if value == nil then return 1 end
    for i, v in ipairs(list) do
        if v[2] == value then
            return i
        end
    end
    return 1 
end


local list_step_1 = generate_list_percent(0, 1000, 1)
local list_step_2 = generate_list_percent(0, 1000, 2)
local list_step_5 = generate_list_percent(0, 1000, 5)
local list_step_20 = generate_list_percent(0, 1000, 20)
local list_step_25 = generate_list_percent(0, 1000, 25)
local list_salvage_sell = generate_list(0, 2100000, 10000)
local list_autoshop_payout = generate_list(0, 2200000, 100000)
local list_cayo_cash_val = generate_list(83250, 2550000, 50000)
local list_cayo_weed_val = generate_list(135000, 2550000, 50000)
local list_cayo_coke_val = generate_list(202500, 2550000, 50000)
local list_cayo_gold_val = generate_list(333333, 2550000, 50000)
local list_cayo_arts_val = generate_list(180000, 2550000, 50000)
local list_fortified_timer = generate_list(0, 1200, 30)

local LAUNCHER_SCRIPT = "fmmc_launcher"
local MISSION_SCRIPT_OLD = "fm_mission_controller"

local LAUNCH_GLOBALS = {
    BASE_LOBBY = 794954,
    STEP_1 = 4718592 + 3539,       
    STEP_2 = 4718592 + 3540,       
    STEP_3 = 4718592 + 3542 + 1,   
    STEP_4 = 4718592 + 192451 + 1, 
    STEP_5 = 4718592 + 3536        
}

local LAUNCH_LOCALS = {
    STATUS = 20056 + 34, 
    PLAYER_COUNT = 20056 + 15,
    TIMER = 20297
}

local CASINO_DATA_BASE = 1973197
local CASINO_FINALE_CHECK = 2685150 + 21

local step1_global = script.globals(LAUNCH_GLOBALS.STEP_1)
local step2_global = script.globals(LAUNCH_GLOBALS.STEP_2)
local step3_global = script.globals(LAUNCH_GLOBALS.STEP_3)
local step4_global = script.globals(LAUNCH_GLOBALS.STEP_4)
local step5_global = script.globals(LAUNCH_GLOBALS.STEP_5)

local launcher_status_local = nil
local player_count_local = nil
local timer_local = nil
local cached_lobby_global = nil
local last_step1_val = -1

local function force_lobby_launch()
    if script.running(LAUNCHER_SCRIPT) then
        if not launcher_status_local then
            launcher_status_local = script.locals(LAUNCHER_SCRIPT, LAUNCH_LOCALS.STATUS)
            player_count_local = script.locals(LAUNCHER_SCRIPT, LAUNCH_LOCALS.PLAYER_COUNT)
            timer_local = script.locals(LAUNCHER_SCRIPT, LAUNCH_LOCALS.TIMER)
        end

        local step1_val = launcher_status_local.int32
        
        if step1_val ~= 0 then
            if step1_val ~= last_step1_val then
                local lobby_idx = LAUNCH_GLOBALS.BASE_LOBBY + 5 + (step1_val * 95) + 75
                cached_lobby_global = script.globals(lobby_idx)
                last_step1_val = step1_val
            end
            
            if cached_lobby_global and cached_lobby_global.int32 > 1 then 
                cached_lobby_global.int32 = 1 
            end
            
            if player_count_local.int32 > 1 then 
                player_count_local.int32 = 1 
            end
            
            step1_global.int32 = 1
            step2_global.int32 = 1
            step3_global.int32 = 1
            step4_global.int32 = 0
            step5_global.int32 = 1
            
            timer_local.int32 = 0
        end
    else
        launcher_status_local = nil
        player_count_local = nil
        timer_local = nil
        cached_lobby_global = nil
        last_step1_val = -1
    end

    util.yield(100) 
end

local function force_casino_data()
    if script.running(MISSION_SCRIPT_OLD) then
        if script.globals(CASINO_FINALE_CHECK).int32 == 1 then
            if account.stats("MP0_H3OPT_APPROACH").int32 == 2 then
                script.globals(CASINO_DATA_BASE + 22).int32 = 3 
            end
            script.globals(CASINO_DATA_BASE + 1).int32 = account.stats("MP0_H3OPT_TARGET").int32 
            script.globals(CASINO_DATA_BASE + 2).bool = true 
            script.globals(CASINO_DATA_BASE + 3).bool = true 
            script.globals(CASINO_DATA_BASE + 4).int32 = account.stats("MP0_H3OPT_DISRUPTSHIP").int32 
            script.globals(CASINO_DATA_BASE + 5).bool = true 
            script.globals(CASINO_DATA_BASE + 6).bool = true 
            script.globals(CASINO_DATA_BASE + 7).bool = true 
            script.globals(CASINO_DATA_BASE + 8).int32 = math.random(6, 8) 
            script.globals(CASINO_DATA_BASE + 10).bool = true 
            script.globals(CASINO_DATA_BASE + 11).bool = true 
            script.globals(CASINO_DATA_BASE + 13).int32 = account.stats("MP0_H3OPT_CREWWEAP").int32 
            script.globals(CASINO_DATA_BASE + 14).int32 = account.stats("MP0_H3OPT_WEAPS").int32 
            script.globals(CASINO_DATA_BASE + 15).int32 = account.stats("MP0_H3OPT_CREWDRIVER").int32
            script.globals(CASINO_DATA_BASE + 16).int32 = account.stats("MP0_H3OPT_VEHS").int32 
            script.globals(CASINO_DATA_BASE + 17).int32 = account.stats("MP0_H3OPT_CREWHACKER").int32 
            script.globals(CASINO_DATA_BASE + 18).int32 = account.stats("MP0_H3OPT_KEYLEVELS").int32 
            script.globals(CASINO_DATA_BASE + 20).int32 = 1 
            script.globals(CASINO_DATA_BASE + 21).int32 = account.stats("MP0_H3OPT_MASKS").int32 
            script.globals(CASINO_DATA_BASE + 24).bool = true 
            script.globals(CASINO_DATA_BASE + 25).int32 = 2047 
            script.globals(CASINO_DATA_BASE + 26).bool = true 
            
            local approach = account.stats("MP0_H3OPT_APPROACH").int32
            local hard_approach = account.stats("MP0_H3_HARD_APPROACH").int32
            script.globals(CASINO_DATA_BASE + 27).bool = (approach == hard_approach)
        end
    end
end

local root = menu.root()

local heistToolMenu = root:submenu("抢劫工具")
local vipWorkMenu = heistToolMenu:submenu("VIP工作")
local payphoneMenu = heistToolMenu:submenu("电话暗杀")
local cayoMenu = heistToolMenu:submenu("佩里科岛抢劫")
local cayoprepsMenu = cayoMenu:submenu("佩里科岛准备选项")
local cayoCutsMenu = cayoMenu:submenu("佩里科岛分红")
local cayotoolsMenu = cayoMenu:submenu("佩里科岛工具")
local difficultyMenu = cayoprepsMenu:submenu("难度")
local approachMenu = cayoprepsMenu:submenu("入侵方式")
local targetMenu = cayoprepsMenu:submenu("主要目标")
local secondaryMenu = cayoprepsMenu:submenu("庄园目标")
local islandTargetMenu = cayoprepsMenu:submenu("岛屿目标")
local loadoutMenu = cayoprepsMenu:submenu("武器配置")
local LootOptionsMenu = cayoprepsMenu:submenu("战利品选项")
local compoundAmountMenu = LootOptionsMenu:submenu("庄园战利品数量")
local islandAmountMenu = LootOptionsMenu:submenu("岛屿战利品数量")
local artsAmountMenu = LootOptionsMenu:submenu("艺术品数量")
local agencyMenu = heistToolMenu:submenu("事务所")
local agencyPrepsMenu = agencyMenu:submenu("事务所准备选项")
local autoshopHeistMenu = heistToolMenu:submenu("改车铺")
local autoshopPrepsMenu = autoshopHeistMenu:submenu("改车铺准备选项")
local autoshopmoneyMenu = autoshopHeistMenu:submenu("改车铺金钱选项")
local autoshopToolMenu = autoshopHeistMenu:submenu("改车铺工具")
local autoshopcontractsmenu = autoshopPrepsMenu:submenu("选择合同")
local salvageMenu = heistToolMenu:submenu("废车回收站")
local casinoHeistMenu = heistToolMenu:submenu("赌场抢劫")
local doomsHeistMenu = heistToolMenu:submenu("末日豪劫")
local classicHeistMenu = heistToolMenu:submenu("公寓抢劫")
local contractsMenu = agencyPrepsMenu:submenu("合同")
local agencyToolsMenu = agencyMenu:submenu("事务所工具")
local salvagePrepsMenu = salvageMenu:submenu("废车回收站准备选项")
local salvageToolsMenu = salvageMenu:submenu("废车回收站工具")
local classicPrepsMenu = classicHeistMenu:submenu("公寓抢劫准备选项")
local classicCutsMenu = classicHeistMenu:submenu("公寓抢劫分红")
local classicToolsMenu = classicHeistMenu:submenu("公寓抢劫工具")
local doomspresetMenu = doomsHeistMenu:submenu("末日豪劫准备预设")
local doomsCutsMenu = doomsHeistMenu:submenu("末日豪劫分红")
local doomsToolsMenu = doomsHeistMenu:submenu("末日豪劫工具")
local doomscutspresetMenu = doomsCutsMenu:submenu("自动末日分红预设")
local cutsMenu = casinoHeistMenu:submenu("赌场分红")
local casinoCutsPresetMenu = cutsMenu:submenu("自动分红预设")
local toolsMenu = casinoHeistMenu:submenu("赌场工具")
local helperMenu = casinoHeistMenu:submenu("赌场助手")
local presetsMenu = casinoHeistMenu:submenu("赌场预设")
local cluckinMenu = heistToolMenu:submenu("当当钟农场突袭")

casinoHeistMenu:button("最高收益为 3,619,000$"):event(menu.event.click, function() end)

local pattern_str = "48 8D 15 ? ? ? ? 41 B8 18 02 00 00 E8"
local scan_result = memory.scan(pattern_str)
local has_gta_plus_addr = nil
local autograb_active = false

if scan_result.value ~= 0 then
    has_gta_plus_addr = scan_result:rip(3, 7)
end

local is_loop_running = false

root:button("解锁 GTA+"):event(menu.event.click, function()
    if is_loop_running then return end
    if not has_gta_plus_addr then return end

    is_loop_running = true

    while is_loop_running do
        has_gta_plus_addr.int32 = 1
        script.globals(1970058).bool = true
        script.globals(1970058):at(3).int32 = 10
        util:yield(10)
    end
end)

casinoHeistMenu:button("跳过游戏厅设置"):event(menu.event.click, function()
    account.stats(27227, 1).bool = true
end)

presetsMenu:button("隐迹潜踪方式"):event(menu.event.click, function()
    
    account.stats("MP0_H3OPT_MASKS").int32 = 4
    account.stats("MP1_H3OPT_MASKS").int32 = 4

    account.stats("MP0_H3OPT_WEAPS").int32 = 1
    account.stats("MP1_H3OPT_WEAPS").int32 = 1

    account.stats("MP0_H3OPT_VEHS").int32 = 3
    account.stats("MP1_H3OPT_VEHS").int32 = 3

    account.stats("MP0_CAS_HEIST_FLOW").int32 = -1
    account.stats("MP1_CAS_HEIST_FLOW").int32 = -1

    account.stats("MP0_H3_LAST_APPROACH").int32 = 0
    account.stats("MP1_H3_LAST_APPROACH").int32 = 0

    account.stats("MP0_H3OPT_APPROACH").int32 = 1
    account.stats("MP1_H3OPT_APPROACH").int32 = 1

    account.stats("MP0_H3_HARD_APPROACH").int32 = 1
    account.stats("MP1_H3_HARD_APPROACH").int32 = 1

    account.stats("MP0_H3OPT_TARGET").int32 = 3
    account.stats("MP1_H3OPT_TARGET").int32 = 3

    account.stats("MP0_H3OPT_POI").int32 = 1023
    account.stats("MP1_H3OPT_POI").int32 = 1023

    account.stats("MP0_H3OPT_ACCESSPOINTS").int32 = 2047
    account.stats("MP1_H3OPT_ACCESSPOINTS").int32 = 2047

    account.stats("MP0_H3OPT_CREWWEAP").int32 = 4
    account.stats("MP1_H3OPT_CREWWEAP").int32 = 4

    account.stats("MP0_H3OPT_CREWDRIVER").int32 = 3
    account.stats("MP1_H3OPT_CREWDRIVER").int32 = 3

    account.stats("MP0_H3OPT_CREWHACKER").int32 = 4
    account.stats("MP1_H3OPT_CREWHACKER").int32 = 4

    account.stats("MP0_H3OPT_DISRUPTSHIP").int32 = 3
    account.stats("MP1_H3OPT_DISRUPTSHIP").int32 = 3

    account.stats("MP0_H3OPT_BODYARMORLVL").int32 = -1
    account.stats("MP1_H3OPT_BODYARMORLVL").int32 = -1

    account.stats("MP0_H3OPT_KEYLEVELS").int32 = 2
    account.stats("MP1_H3OPT_KEYLEVELS").int32 = 2

    account.stats("MP0_H3OPT_BITSET1").int32 = 127
    account.stats("MP1_H3OPT_BITSET1").int32 = 127

    account.stats("MP0_H3OPT_BITSET0").int32 = 262270
    account.stats("MP1_H3OPT_BITSET0").int32 = 262270

    account.stats("MP0_CAS_HEIST_FLOW").int32 = -1
    account.stats("MP1_CAS_HEIST_FLOW").int32 = -1


    script.locals("gb_casino_heist_planning", 210).int32 = 2
end)

presetsMenu:button("兵不厌诈方式"):event(menu.event.click, function()
    local prefix0 = "MP0_"
    local prefix1 = "MP1_"

    account.stats(prefix0 .. "H3OPT_MASKS").int32 = 2
    account.stats(prefix1 .. "H3OPT_MASKS").int32 = 2
    account.stats(prefix0 .. "H3OPT_WEAPS").int32 = 1
    account.stats(prefix1 .. "H3OPT_WEAPS").int32 = 1
    account.stats(prefix0 .. "H3OPT_VEHS").int32 = 3
    account.stats(prefix1 .. "H3OPT_VEHS").int32 = 3
    account.stats(prefix0 .. "CAS_HEIST_FLOW").int32 = -1
    account.stats(prefix1 .. "CAS_HEIST_FLOW").int32 = -1
    account.stats(prefix0 .. "H3_LAST_APPROACH").int32 = 0
    account.stats(prefix1 .. "H3_LAST_APPROACH").int32 = 0
    account.stats(prefix0 .. "H3OPT_APPROACH").int32 = 2
    account.stats(prefix1 .. "H3OPT_APPROACH").int32 = 2
    account.stats(prefix0 .. "H3_HARD_APPROACH").int32 = 2
    account.stats(prefix1 .. "H3_HARD_APPROACH").int32 = 2
    account.stats(prefix0 .. "H3OPT_TARGET").int32 = 3
    account.stats(prefix1 .. "H3OPT_TARGET").int32 = 3
    account.stats(prefix0 .. "H3OPT_POI").int32 = 1023
    account.stats(prefix1 .. "H3OPT_POI").int32 = 1023
    account.stats(prefix0 .. "H3OPT_ACCESSPOINTS").int32 = 2047
    account.stats(prefix1 .. "H3OPT_ACCESSPOINTS").int32 = 2047
    account.stats(prefix0 .. "H3OPT_CREWWEAP").int32 = 4
    account.stats(prefix1 .. "H3OPT_CREWWEAP").int32 = 4
    account.stats(prefix0 .. "H3OPT_CREWDRIVER").int32 = 3
    account.stats(prefix1 .. "H3OPT_CREWDRIVER").int32 = 3
    account.stats(prefix0 .. "H3OPT_CREWHACKER").int32 = 4
    account.stats(prefix1 .. "H3OPT_CREWHACKER").int32 = 4
    account.stats(prefix0 .. "H3OPT_DISRUPTSHIP").int32 = 3
    account.stats(prefix1 .. "H3OPT_DISRUPTSHIP").int32 = 3
    account.stats(prefix0 .. "H3OPT_BODYARMORLVL").int32 = -1
    account.stats(prefix1 .. "H3OPT_BODYARMORLVL").int32 = -1
    account.stats(prefix0 .. "H3OPT_KEYLEVELS").int32 = 2
    account.stats(prefix1 .. "H3OPT_KEYLEVELS").int32 = 2
    account.stats(prefix0 .. "H3OPT_BITSET1").int32 = 159
    account.stats(prefix1 .. "H3OPT_BITSET1").int32 = 159
    account.stats(prefix0 .. "H3OPT_BITSET0").int32 = 524118
    account.stats(prefix1 .. "H3OPT_BITSET0").int32 = 524118
    account.stats(prefix0 .. "CAS_HEIST_FLOW").int32 = -1
    account.stats(prefix1 .. "CAS_HEIST_FLOW").int32 = -1

    script.locals("gb_casino_heist_planning", 212).int32 = 2
end)

presetsMenu:button("气势汹汹方式"):event(menu.event.click, function()
    local prefix0 = "MP0_"
    local prefix1 = "MP1_"

    account.stats(prefix0 .. "H3OPT_MASKS").int32 = 4
    account.stats(prefix1 .. "H3OPT_MASKS").int32 = 4
    account.stats(prefix0 .. "H3OPT_WEAPS").int32 = 1
    account.stats(prefix1 .. "H3OPT_WEAPS").int32 = 1
    account.stats(prefix0 .. "H3OPT_VEHS").int32 = 3
    account.stats(prefix1 .. "H3OPT_VEHS").int32 = 3
    account.stats(prefix0 .. "CAS_HEIST_FLOW").int32 = -1
    account.stats(prefix1 .. "CAS_HEIST_FLOW").int32 = -1
    account.stats(prefix0 .. "H3_LAST_APPROACH").int32 = 0
    account.stats(prefix1 .. "H3_LAST_APPROACH").int32 = 0
    account.stats(prefix0 .. "H3OPT_APPROACH").int32 = 3
    account.stats(prefix1 .. "H3OPT_APPROACH").int32 = 3
    account.stats(prefix0 .. "H3_HARD_APPROACH").int32 = 3
    account.stats(prefix1 .. "H3_HARD_APPROACH").int32 = 3
    account.stats(prefix0 .. "H3OPT_TARGET").int32 = 3
    account.stats(prefix1 .. "H3OPT_TARGET").int32 = 3
    account.stats(prefix0 .. "H3OPT_POI").int32 = 1023
    account.stats(prefix1 .. "H3OPT_POI").int32 = 1023
    account.stats(prefix0 .. "H3OPT_ACCESSPOINTS").int32 = 2047
    account.stats(prefix1 .. "H3OPT_ACCESSPOINTS").int32 = 2047
    account.stats(prefix0 .. "H3OPT_CREWWEAP").int32 = 4
    account.stats(prefix1 .. "H3OPT_CREWWEAP").int32 = 4
    account.stats(prefix0 .. "H3OPT_CREWDRIVER").int32 = 3
    account.stats(prefix1 .. "H3OPT_CREWDRIVER").int32 = 3
    account.stats(prefix0 .. "H3OPT_CREWHACKER").int32 = 4
    account.stats(prefix1 .. "H3OPT_CREWHACKER").int32 = 4
    account.stats(prefix0 .. "H3OPT_DISRUPTSHIP").int32 = 3
    account.stats(prefix1 .. "H3OPT_DISRUPTSHIP").int32 = 3
    account.stats(prefix0 .. "H3OPT_BODYARMORLVL").int32 = -1
    account.stats(prefix1 .. "H3OPT_BODYARMORLVL").int32 = -1
    account.stats(prefix0 .. "H3OPT_KEYLEVELS").int32 = 2
    account.stats(prefix1 .. "H3OPT_KEYLEVELS").int32 = 2
    account.stats(prefix0 .. "H3OPT_BITSET1").int32 = 799
    account.stats(prefix1 .. "H3OPT_BITSET1").int32 = 799
    account.stats(prefix0 .. "H3OPT_BITSET0").int32 = 3670102
    account.stats(prefix1 .. "H3OPT_BITSET0").int32 = 3670102
    account.stats(prefix0 .. "CAS_HEIST_FLOW").int32 = -1
    account.stats(prefix1 .. "CAS_HEIST_FLOW").int32 = -1


    script.locals("gb_casino_heist_planning", 212).int32 = 2
end)

presetsMenu:button("重置抢劫准备"):event(menu.event.click, function()

    local prefix0 = "MP0_"
    local prefix1 = "MP1_"

    account.stats(prefix0 .. "H3OPT_DISRUPTSHIP").int32 = 0
    account.stats(prefix1 .. "H3OPT_DISRUPTSHIP").int32 = 0
    account.stats(prefix0 .. "H3OPT_BODYARMORLVL").int32 = 0
    account.stats(prefix1 .. "H3OPT_BODYARMORLVL").int32 = 0
    account.stats(prefix0 .. "H3OPT_CREWWEAP").int32 = 0
    account.stats(prefix1 .. "H3OPT_CREWWEAP").int32 = 0
    account.stats(prefix0 .. "H3OPT_CREWDRIVER").int32 = 0
    account.stats(prefix1 .. "H3OPT_CREWDRIVER").int32 = 0
    account.stats(prefix0 .. "H3OPT_CREWHACKER").int32 = 0
    account.stats(prefix1 .. "H3OPT_CREWHACKER").int32 = 0
    account.stats(prefix0 .. "H3OPT_KEYLEVELS").int32 = 0
    account.stats(prefix1 .. "H3OPT_KEYLEVELS").int32 = 0
    account.stats(prefix0 .. "H3OPT_MODVEH").int32 = 0
    account.stats(prefix1 .. "H3OPT_MODVEH").int32 = 0
    account.stats(prefix0 .. "H3OPT_MASKS").int32 = 0
    account.stats(prefix1 .. "H3OPT_MASKS").int32 = 0
    account.stats(prefix0 .. "H3OPT_WEAPS").int32 = 0
    account.stats(prefix1 .. "H3OPT_WEAPS").int32 = 0
    account.stats(prefix0 .. "H3OPT_VEHS").int32 = 0
    account.stats(prefix1 .. "H3OPT_VEHS").int32 = 0
    account.stats(prefix0 .. "H3OPT_APPROACH").int32 = 0
    account.stats(prefix1 .. "H3OPT_APPROACH").int32 = 0
    account.stats(prefix0 .. "H3OPT_BITSET0").int32 = 0
    account.stats(prefix1 .. "H3OPT_BITSET0").int32 = 0
    account.stats(prefix0 .. "H3OPT_ACCESSPOINTS").int32 = 0
    account.stats(prefix1 .. "H3OPT_ACCESSPOINTS").int32 = 0
    account.stats(prefix0 .. "H3OPT_TARGET").int32 = 0
    account.stats(prefix1 .. "H3OPT_TARGET").int32 = 0
    account.stats(prefix0 .. "H3OPT_POI").int32 = 0
    account.stats(prefix1 .. "H3OPT_POI").int32 = 0
    account.stats(prefix0 .. "H3OPT_BITSET1").int32 = 0
    account.stats(prefix1 .. "H3OPT_BITSET1").int32 = 0
    account.stats(prefix0 .. "H3_PARTIALPASS").int32 = 0
    account.stats(prefix1 .. "H3_PARTIALPASS").int32 = 0
    account.stats(prefix0 .. "CAS_HEIST_NOTS").int32 = 0
    account.stats(prefix1 .. "CAS_HEIST_NOTS").int32 = 0
    account.stats(prefix0 .. "CAS_HEIST_FLOW").int32 = -1
    account.stats(prefix1 .. "CAS_HEIST_FLOW").int32 = -1
    account.stats(prefix0 .. "H3_LAST_APPROACH").int32 = 0
    account.stats(prefix1 .. "H3_LAST_APPROACH").int32 = 0
    account.stats(prefix0 .. "H3_HARD_APPROACH").int32 = 0
    account.stats(prefix1 .. "H3_HARD_APPROACH").int32 = 0
    account.stats(prefix0 .. "H3_SKIPCOUNT").int32 = 0
    account.stats(prefix1 .. "H3_SKIPCOUNT").int32 = 0
    account.stats(prefix0 .. "H3_MISSIONSKIPPED").int32 = 0
    account.stats(prefix1 .. "H3_MISSIONSKIPPED").int32 = 0
    account.stats(prefix0 .. "H3_BOARD_DIALOGUE0").int32 = 0
    account.stats(prefix1 .. "H3_BOARD_DIALOGUE0").int32 = 0
    account.stats(prefix0 .. "H3_BOARD_DIALOGUE1").int32 = 0
    account.stats(prefix1 .. "H3_BOARD_DIALOGUE1").int32 = 0
    account.stats(prefix0 .. "H3_BOARD_DIALOGUE2").int32 = 0
    account.stats(prefix1 .. "H3_BOARD_DIALOGUE2").int32 = 0
    account.stats(prefix0 .. "H3_VEHICLESUSED").int32 = 0
    account.stats(prefix1 .. "H3_VEHICLESUSED").int32 = 0
    account.stats(prefix0 .. "MPPLY_H3_COOLDOWN").int32 = 0
    account.stats(prefix1 .. "MPPLY_H3_COOLDOWN").int32 = 0
    account.stats(prefix0 .. "H3_COMPLETEDPOSIX").int32 = 0
    account.stats("MP1_H3_COMPLETEDPOSIX").int32 = 0

    script.locals("gb_casino_heist_planning", 212).int32 = 2
end)

local casino_cuts_base = 1973231 + 1497 + 736 + 92
local default_idx_0_step2 = find_index(list_step_2, 0)

local casino_combo_cut1 = cutsMenu:combo_int("主机分红 %", list_step_2, menu.type.scroll)
casino_combo_cut1.value = default_idx_0_step2

local casino_combo_cut2 = cutsMenu:combo_int("玩家 2 分红 %", list_step_2, menu.type.scroll)
casino_combo_cut2.value = default_idx_0_step2

local casino_combo_cut3 = cutsMenu:combo_int("玩家 3 分红 %", list_step_2, menu.type.scroll)
casino_combo_cut3.value = default_idx_0_step2

local casino_combo_cut4 = cutsMenu:combo_int("玩家 4 分红 %", list_step_2, menu.type.scroll)
casino_combo_cut4.value = default_idx_0_step2

local function get_casino_cut_value(combo_obj)
    if combo_obj.value > #list_step_2 then return 120 end
    return list_step_2[combo_obj.value][2]
end

local function apply_casino_cuts(cut1, cut2, cut3, cut4)
    script.globals(casino_cuts_base + 1).int32 = cut1
    script.globals(casino_cuts_base + 2).int32 = cut2
    script.globals(casino_cuts_base + 3).int32 = cut3
    script.globals(casino_cuts_base + 4).int32 = cut4
end


cutsMenu:button("设置所有分红"):event(menu.event.click, function()
    local c1 = get_casino_cut_value(casino_combo_cut1)
    local c2 = get_casino_cut_value(casino_combo_cut2)
    local c3 = get_casino_cut_value(casino_combo_cut3)
    local c4 = get_casino_cut_value(casino_combo_cut4)
    apply_casino_cuts(c1, c2, c3, c4)
end)

local function apply_casino_preset(c1, c2, c3, c4)

    apply_casino_cuts(c1, c2, c3, c4)

    local r1 = math.floor(c1 / 2 + 0.5) * 2
    local r2 = math.floor(c2 / 2 + 0.5) * 2
    local r3 = math.floor(c3 / 2 + 0.5) * 2
    local r4 = math.floor(c4 / 2 + 0.5) * 2

    casino_combo_cut1.value = find_index(list_step_2, r1)
    casino_combo_cut2.value = find_index(list_step_2, r2)
    casino_combo_cut3.value = find_index(list_step_2, r3)
    casino_combo_cut4.value = find_index(list_step_2, r4)
end


cutsMenu:button("强制所有玩家准备就绪"):event(menu.event.click, function()
    for i = 0, 3 do
        script.globals(1977594 + 1 + (i * 68) + 8).int32 = 1
    end
end)

casinoCutsPresetMenu:button("所有人 100%"):event(menu.event.click, function()
    apply_casino_preset(100, 100, 100, 100)
end)

casinoCutsPresetMenu:button("主机 0%，其他人 100%"):event(menu.event.click, function()
    apply_casino_preset(0, 100, 100, 100)
end)

casinoCutsPresetMenu:button("所有人 110%"):event(menu.event.click, function()
    apply_casino_preset(110, 110, 110, 110)
end)

casinoCutsPresetMenu:button("主机 0%，其他人 110%"):event(menu.event.click, function()
    apply_casino_preset(0, 110, 110, 110) 
end)

local casino_running = false 

casinoHeistMenu:toggle("赌场单人启动"):event(menu.event.click, function(toggle)
    if toggle.value then
        casino_running = true 
        force_casino_data() 
        util.create_job(function()
            while casino_running do
                force_lobby_launch()
                util.yield(1000) 
            end
        end)
    else
        casino_running = false 
        if script.running(LAUNCHER_SCRIPT) then
            local step1_val = script.locals(LAUNCHER_SCRIPT, LAUNCH_LOCALS.STATUS).int32
            if step1_val ~= 0 then
                local lobby_idx = LAUNCH_GLOBALS.BASE_LOBBY + 5 + (step1_val * 95) + 75
                script.globals(lobby_idx).int32 = 2
                script.locals(LAUNCHER_SCRIPT, LAUNCH_LOCALS.PLAYER_COUNT).int32 = 2
                script.globals(LAUNCH_GLOBALS.STEP_1).int32 = 1
                script.globals(LAUNCH_GLOBALS.STEP_2).int32 = 1
                script.globals(LAUNCH_GLOBALS.STEP_3).int32 = 2 
                script.globals(LAUNCH_GLOBALS.STEP_4).int32 = 11 
            end
        end
    end
end)

toolsMenu:button("指纹破解"):event(menu.event.click, function()

    local val1 = script.locals("fm_mission_controller", 54042).int32
    if (val1 & 1) == 0 then
        script.locals("fm_mission_controller", 54042).int32 = val1 | 1
    end
    
    local val2 = script.locals("fm_mission_controller", 55107).int32
    if (val2 & 1) == 0 then
        script.locals("fm_mission_controller", 55107).int32 = val2 | 1
    end
end)

toolsMenu:button("即时键盘破解"):event(menu.event.click, function()
    script.locals("fm_mission_controller", 55108).int32 = 5
end)


toolsMenu:button("即时金库钻头"):event(menu.event.click, function()

    local target = script.locals("fm_mission_controller", 10551 + 37).int32
    script.locals("fm_mission_controller", 10551 + 7).int32 = target
    script.locals("fm_mission_controller", 10551 + 12).float = 1.0  
    script.locals("fm_mission_controller", 10551 + 2).int32 = 7
    local bits = script.locals("fm_mission_controller", 10551).int32
    script.locals("fm_mission_controller", 10551).int32 = bits | (1 << 12)
end)

helperMenu:button("跳过当前目标（卡住时使用）"):event(menu.event.click, function()
    local scriptName = "fm_mission_controller"
    if script.running(scriptName) then
        local iServerBitSet1 = 20397 
        local val = script.locals(scriptName, iServerBitSet1).int32
        script.locals(scriptName, iServerBitSet1).int32 = val | (1 << 17)
    end
end)


toolsMenu:button("修复双门禁卡卡住"):event(menu.event.click, function()
    script.locals("fm_mission_controller", 63638).int32 = 5
end)


toolsMenu:button("移除抢劫冷却"):event(menu.event.click, function()
    local prefix0 = "MP0_"
    local prefix1 = "MP1_"

    account.stats(prefix0 .. "H3_COMPLETEDPOSIX").int32 = -1
    account.stats(prefix1 .. "H3_COMPLETEDPOSIX").int32 = -1
    account.stats(prefix0 .. "MPPLY_H3_COOLDOWN").int32 = -1
    account.stats(prefix1 .. "MPPLY_H3_COOLDOWN").int32 = -1
end)


toolsMenu:button("设置团队生命为 100"):event(menu.event.click, function()  
        local lives_lost_offset = 22126 
        local lives_lost_value = -100  
        script.locals("fm_mission_controller", lives_lost_offset).int32 = lives_lost_value
end)

toolsMenu:button("立即完成（气势汹汹）"):event(menu.event.click, function()
    script.force_host("fm_mission_controller")
    script.locals("fm_mission_controller", 20395).int32 = 12
    script.locals("fm_mission_controller", 22136).int32 = 80
    script.locals("fm_mission_controller", 23081).int32 = 10000000
    script.locals("fm_mission_controller", 29017).int32 = 99999
    script.locals("fm_mission_controller", 32541).int32 = 99999
end)

toolsMenu:button("立即完成（兵不厌诈/隐迹潜踪）"):event(menu.event.click, function()
    script.force_host("fm_mission_controller")
    script.locals("fm_mission_controller", 21457).int32 = 5
    script.locals("fm_mission_controller", 22136).int32 = 80
    script.locals("fm_mission_controller", 23081).int32 = 10000000
    script.locals("fm_mission_controller", 29017).int32 = 99999
    script.locals("fm_mission_controller", 32541).int32 = 99999
end)

doomsHeistMenu:button("最高收益为 2,550,000$"):event(menu.event.click, function() end)

doomspresetMenu:button("预设：第一章 数据泄露"):event(menu.event.click, function()
    local prefix0 = "MP0_"
    local prefix1 = "MP1_"

    account.stats(prefix0 .. "GANGOPS_FLOW_MISSION_PROG").int32 = 503
    account.stats(prefix1 .. "GANGOPS_FLOW_MISSION_PROG").int32 = 503
    account.stats(prefix0 .. "GANGOPS_HEIST_STATUS").int32 = -229383
    account.stats(prefix1 .. "GANGOPS_HEIST_STATUS").int32 = -229383
    account.stats(prefix0 .. "GANGOPS_FLOW_NOTIFICATIONS").int32 = 1557
    account.stats(prefix1 .. "GANGOPS_FLOW_NOTIFICATIONS").int32 = 1557

    script.locals("gb_gang_ops_planning", 211).int32 = 6

end)

doomspresetMenu:button("预设：第二章 博格丹危机"):event(menu.event.click, function()
    local prefix0 = "MP0_"
    local prefix1 = "MP1_"

    account.stats(prefix0 .. "GANGOPS_FLOW_MISSION_PROG").int32 = 240
    account.stats(prefix1 .. "GANGOPS_FLOW_MISSION_PROG").int32 = 240
    account.stats(prefix0 .. "GANGOPS_HEIST_STATUS").int32 = -229378
    account.stats(prefix1 .. "GANGOPS_HEIST_STATUS").int32 = -229378
    account.stats(prefix0 .. "GANGOPS_FLOW_NOTIFICATIONS").int32 = 1557
    account.stats(prefix1 .. "GANGOPS_FLOW_NOTIFICATIONS").int32 = 1557

    script.locals("gb_gang_ops_planning", 211).int32 = 6
end)

doomspresetMenu:button("预设：第三章 末日将至"):event(menu.event.click, function()
    local prefix0 = "MP0_"
    local prefix1 = "MP1_"

    account.stats(prefix0 .. "GANGOPS_FLOW_MISSION_PROG").int32 = 16368
    account.stats(prefix1 .. "GANGOPS_FLOW_MISSION_PROG").int32 = 16368
    account.stats(prefix0 .. "GANGOPS_HEIST_STATUS").int32 = -229380
    account.stats(prefix1 .. "GANGOPS_HEIST_STATUS").int32 = -229380
    account.stats(prefix0 .. "GANGOPS_FLOW_NOTIFICATIONS").int32 = 1557
    account.stats(prefix1 .. "GANGOPS_FLOW_NOTIFICATIONS").int32 = 1557

    script.locals("gb_gang_ops_planning", 211).int32 = 6
end)

doomspresetMenu:button("重置末日豪劫"):event(menu.event.click, function()
    local prefix0 = "MP0_"
    local prefix1 = "MP1_"

    account.stats(prefix0 .. "GANGOPS_FLOW_MISSION_PROG").int32 = 503
    account.stats(prefix1 .. "GANGOPS_FLOW_MISSION_PROG").int32 = 503
    account.stats(prefix0 .. "GANGOPS_HEIST_STATUS").int32 = 0
    account.stats(prefix1 .. "GANGOPS_HEIST_STATUS").int32 = 0
    account.stats(prefix0 .. "GANGOPS_FLOW_NOTIFICATIONS").int32 = 1557
    account.stats(prefix1 .. "GANGOPS_FLOW_NOTIFICATIONS").int32 = 1557

    script.locals("gb_gang_ops_planning", 211).int32 = 6
end)

local dooms_cuts_base = 1969405
local default_idx_0_step5 = find_index(list_step_5, 0)

local dooms_combo_cut1 = doomsCutsMenu:combo_int("主机分红 %", list_step_5, menu.type.scroll)
dooms_combo_cut1.value = default_idx_0_step5

local dooms_combo_cut2 = doomsCutsMenu:combo_int("玩家 2 分红 %", list_step_5, menu.type.scroll)
dooms_combo_cut2.value = default_idx_0_step5

local dooms_combo_cut3 = doomsCutsMenu:combo_int("玩家 3 分红 %", list_step_5, menu.type.scroll)
dooms_combo_cut3.value = default_idx_0_step5

local dooms_combo_cut4 = doomsCutsMenu:combo_int("玩家 4 分红 %", list_step_5, menu.type.scroll)
dooms_combo_cut4.value = default_idx_0_step5

local function get_dooms_cut_value(combo_obj)
    if combo_obj.value > #list_step_5 then return 150 end
    return list_step_5[combo_obj.value][2]
end

local function apply_dooms_cuts(cut1, cut2, cut3, cut4)
    script.globals(dooms_cuts_base + 1).int32 = cut1
    script.globals(dooms_cuts_base + 2).int32 = cut2
    script.globals(dooms_cuts_base + 3).int32 = cut3
    script.globals(dooms_cuts_base + 4).int32 = cut4
end

doomsCutsMenu:button("应用分红"):event(menu.event.click, function()
    local c1 = get_dooms_cut_value(dooms_combo_cut1)
    local c2 = get_dooms_cut_value(dooms_combo_cut2)
    local c3 = get_dooms_cut_value(dooms_combo_cut3)
    local c4 = get_dooms_cut_value(dooms_combo_cut4)
    apply_dooms_cuts(c1, c2, c3, c4)
end)

local function apply_dooms_preset(c1, c2, c3, c4)
    apply_dooms_cuts(c1, c2, c3, c4)
    local r1 = math.floor(c1 / 5 + 0.5) * 5
    local r2 = math.floor(c2 / 5 + 0.5) * 5
    local r3 = math.floor(c3 / 5 + 0.5) * 5
    local r4 = math.floor(c4 / 5 + 0.5) * 5

    dooms_combo_cut1.value = find_index(list_step_5, r1)
    dooms_combo_cut2.value = find_index(list_step_5, r2)
    dooms_combo_cut3.value = find_index(list_step_5, r3)
    dooms_combo_cut4.value = find_index(list_step_5, r4)
end

doomscutspresetMenu:button("第一章 数据泄露"):event(menu.event.click, function()
    apply_dooms_preset(261, 261, 261, 261)
end)

doomscutspresetMenu:button("第二章 博格丹危机"):event(menu.event.click, function()
    apply_dooms_preset(178, 178, 178, 178)
end)

doomscutspresetMenu:button("第三章 末日将至"):event(menu.event.click, function()
    apply_dooms_preset(141, 141, 141, 141)
end)

local Ready = {
    Player1 = { type = "int", global = 1882717 + 1 + (0 * 315) + 55 },
    Player2 = { type = "int", global = 1882717 + 1 + (1 * 315) + 55 + 1 },
    Player3 = { type = "int", global = 1882717 + 1 + (2 * 315) + 55 + 2 },
    Player4 = { type = "int", global = 1882717 + 1 + (3 * 315) + 55 + 3 },
}

doomsCutsMenu:button("强制所有玩家准备就绪"):event(menu.event.click, function()
    script.globals(Ready.Player1.global).int32 = 1
    script.globals(Ready.Player2.global).int32 = 1
    script.globals(Ready.Player3.global).int32 = 1
    script.globals(Ready.Player4.global).int32 = 1
end)

local dday_running = false

doomsHeistMenu:toggle("末日豪劫单人启动"):event(menu.event.click, function(toggle)
    if toggle.value then
        dday_running = true 
        util.create_job(function()
            while dday_running do
                force_lobby_launch()
                util.yield(1000) 
            end
        end)
    else
        dday_running = false 
        if script.running(LAUNCHER_SCRIPT) then
            local step1_val = script.locals(LAUNCHER_SCRIPT, LAUNCH_LOCALS.STATUS).int32
            if step1_val ~= 0 then
                local lobby_idx = LAUNCH_GLOBALS.BASE_LOBBY + 5 + (step1_val * 95) + 75
                script.globals(lobby_idx).int32 = 2
                script.locals(LAUNCHER_SCRIPT, LAUNCH_LOCALS.PLAYER_COUNT).int32 = 2
                script.globals(LAUNCH_GLOBALS.STEP_1).int32 = 1
                script.globals(LAUNCH_GLOBALS.STEP_2).int32 = 1
                script.globals(LAUNCH_GLOBALS.STEP_3).int32 = 2
                script.globals(LAUNCH_GLOBALS.STEP_4).int32 = 11
            end
        end
    end
end)

doomsToolsMenu:button("绕过破解：第一章 数据泄露"):event(menu.event.click, function()
        script.locals("fm_mission_controller", 1541).int32 = 2
end)

doomsToolsMenu:button("绕过破解：第三章 末日"):event(menu.event.click, function()
        script.locals("fm_mission_controller", 1435).int32 = 3
end)

doomsToolsMenu:button("即时服务器农场破解"):event(menu.event.click, function()
    script.locals("fm_mission_controller", 1439).int32 = 2
end)

doomsToolsMenu:button("即时激光破解"):event(menu.event.click, function()
    script.locals("fm_mission_controller", 1298 + 135).int32 = 3
end)

doomsToolsMenu:button("设置团队生命为 100"):event(menu.event.click, function()    
        local lives_lost_offset = 22126 
        local lives_lost_value = -100   
        script.locals("fm_mission_controller", lives_lost_offset).int32 = lives_lost_value
end)

doomsToolsMenu:button("立即完成（全部章节）"):event(menu.event.click, function()
    if script.force_host("fm_mission_controller") then
        util.yield(1000)
        script.locals("fm_mission_controller", 20395).int32 = 12
        script.locals("fm_mission_controller", 22136).int32 = 150
        script.locals("fm_mission_controller", 29017).int32 = 99999
        script.locals("fm_mission_controller", 32541).int32 = 99999
        script.locals("fm_mission_controller", 32569).int32 = 80
    end
end)

classicHeistMenu:button("最高收益为 3,000,000$"):event(menu.event.click, function() end)

classicPrepsMenu:button("跳过公寓抢劫准备"):event(menu.event.click, function()
    account.stats("MP0_HEIST_PLANNING_STAGE").int32 = -1
    account.stats("MP1_HEIST_PLANNING_STAGE").int32 = -1
end)

classicPrepsMenu:button("重绘抢劫面板"):event(menu.event.click, function()
    script.globals(1936048).int32 = 22
end)

local apt_running = false 

classicHeistMenu:toggle("公寓抢劫单人启动"):event(menu.event.click, function(toggle)
    if toggle.value then
        apt_running = true 
        
        util.create_job(function()
            while apt_running do
                force_lobby_launch()
                util.yield(1000) 
            end
        end)
    else
        apt_running = false 

        if script.running(LAUNCHER_SCRIPT) then
            local isFleeca = account.stats("HEIST_MISSION_RCONT_ID_1").int32 == 1122849505
            local needed = isFleeca and 2 or 4
            
            local step1_val = script.locals(LAUNCHER_SCRIPT, LAUNCH_LOCALS.STATUS).int32
            if step1_val ~= 0 then
                local lobby_idx = LAUNCH_GLOBALS.BASE_LOBBY + 5 + (step1_val * 95) + 75
                script.globals(lobby_idx).int32 = needed
                script.locals(LAUNCHER_SCRIPT, LAUNCH_LOCALS.PLAYER_COUNT).int32 = needed
                script.globals(LAUNCH_GLOBALS.STEP_1).int32 = needed
                script.globals(LAUNCH_GLOBALS.STEP_2).int32 = needed 
                script.globals(LAUNCH_GLOBALS.STEP_3).int32 = 1
                script.globals(LAUNCH_GLOBALS.STEP_4).int32 = 0
            end
        end
    end
end)

classicToolsMenu:button("绕过全福银行破解"):event(menu.event.click, function()
        script.locals("fm_mission_controller", 12247).int32 = 7
end)

classicToolsMenu:button("即时钻头"):event(menu.event.click, function()
    script.locals("fm_mission_controller", 10511 + 11).float = 1.0
end)

classicToolsMenu:button("绕过太平洋破解"):event(menu.event.click, function()
        script.locals("fm_mission_controller", 10215).int32 = 9
end)

classicToolsMenu:button("清除公寓抢劫冷却"):event(menu.event.click, function()

    local playerId = players.me().id
    local cooldownGlobal = 1877303 + 1 + (playerId * 77) + 76
    script.globals(cooldownGlobal).int32 = -1

end)

classicToolsMenu:button("设置团队生命为 100"):event(menu.event.click, function()    
        local lives_lost_offset = 22126 
        local lives_lost_value = -100  
        script.locals("fm_mission_controller", lives_lost_offset).int32 = lives_lost_value
end)



classicToolsMenu:button("立即完成（太平洋标准银行）"):event(menu.event.click, function()
    if script.force_host("fm_mission_controller") then
        util.yield(1000) 
        script.locals("fm_mission_controller", 21457).int32 = 5        
        script.locals("fm_mission_controller", 22136).int32 = 80       
        script.locals("fm_mission_controller", 23081).int32 = 10000000 
        script.locals("fm_mission_controller", 29017).int32 = 99999    
        script.locals("fm_mission_controller", 32541).int32 = 99999    
    end
end)

classicToolsMenu:button("立即完成（其他公寓抢劫）"):event(menu.event.click, function()
    if script.force_host("fm_mission_controller") then
        util.yield(1000) 
        script.locals("fm_mission_controller", 20395).int32 = 12      
        script.locals("fm_mission_controller", 23081).int32 = 99999    
        script.locals("fm_mission_controller", 29017).int32 = 99999    
        script.locals("fm_mission_controller", 32541).int32 = 99999   
    end
end)

classicHeistMenu:button("解锁所有公寓抢劫任务"):event(menu.event.click, function()

    local fleeca_id = script.tunables("ROOT_ID_HASH_THE_FLECCA_JOB").int32
    local prison_id = script.tunables("ROOT_ID_HASH_THE_PRISON_BREAK").int32
    local humane_id = script.tunables("ROOT_ID_HASH_THE_HUMANE_LABS_RAID").int32
    local series_a_id = script.tunables("ROOT_ID_HASH_SERIES_A_FUNDING").int32
    local pacific_id = script.tunables("ROOT_ID_HASH_THE_PACIFIC_STANDARD_JOB").int32

    account.stats("MP0_HEIST_SAVED_STRAND_0").int32 = fleeca_id
    account.stats("MP0_HEIST_SAVED_STRAND_0_L").int32 = 5
    account.stats("MP1_HEIST_SAVED_STRAND_0").int32 = fleeca_id
    account.stats("MP1_HEIST_SAVED_STRAND_0_L").int32 = 5

    account.stats("MP0_HEIST_SAVED_STRAND_1").int32 = prison_id
    account.stats("MP0_HEIST_SAVED_STRAND_1_L").int32 = 5
    account.stats("MP1_HEIST_SAVED_STRAND_1").int32 = prison_id
    account.stats("MP1_HEIST_SAVED_STRAND_1_L").int32 = 5


    account.stats("MP0_HEIST_SAVED_STRAND_2").int32 = humane_id
    account.stats("MP0_HEIST_SAVED_STRAND_2_L").int32 = 5
    account.stats("MP1_HEIST_SAVED_STRAND_2").int32 = humane_id
    account.stats("MP1_HEIST_SAVED_STRAND_2_L").int32 = 5

    account.stats("MP0_HEIST_SAVED_STRAND_3").int32 = series_a_id
    account.stats("MP0_HEIST_SAVED_STRAND_3_L").int32 = 5
    account.stats("MP1_HEIST_SAVED_STRAND_3").int32 = series_a_id
    account.stats("MP1_HEIST_SAVED_STRAND_3_L").int32 = 5

    account.stats("MP0_HEIST_SAVED_STRAND_4").int32 = pacific_id
    account.stats("MP0_HEIST_SAVED_STRAND_4_L").int32 = 5
    account.stats("MP1_HEIST_SAVED_STRAND_4").int32 = pacific_id
    account.stats("MP1_HEIST_SAVED_STRAND_4_L").int32 = 5
end)

local classicCutsHelper = classicCutsMenu:submenu("自动抢劫分红预设")
local default_idx_0_step20 = find_index(list_step_20, 0)

local combo_cut1 = classicCutsMenu:combo_int("抢劫分红 1（主机）", list_step_20, menu.type.scroll)
combo_cut1.value = default_idx_0_step20

local combo_cut2 = classicCutsMenu:combo_int("抢劫分红 2", list_step_20, menu.type.scroll)
combo_cut2.value = default_idx_0_step20

local combo_cut3 = classicCutsMenu:combo_int("抢劫分红 3", list_step_20, menu.type.scroll)
combo_cut3.value = default_idx_0_step20

local combo_cut4 = classicCutsMenu:combo_int("抢劫分红 4", list_step_20, menu.type.scroll)
combo_cut4.value = default_idx_0_step20

local function get_selected_cut_value(combo_obj)
    if combo_obj.value > #list_step_20 then return 100 end
    return list_step_20[combo_obj.value][2]
end

local function apply_cuts_from_values(cut1, cut2, cut3, cut4)
    local base_global = 1936013
    local base_local = 1937981 + 3008

    local total_cut = cut1 + cut2 + cut3 + cut4
    local over_cap = total_cut - 100

    if over_cap > 0 then
        script.globals(base_global + 1 + 1).int32 = -over_cap
    else
        script.globals(base_global + 1 + 1).int32 = 0
    end

    script.globals(base_global + 1 + 2).int32 = cut2
    script.globals(base_global + 1 + 3).int32 = cut3
    script.globals(base_global + 1 + 4).int32 = cut4

    script.globals(base_local + 1).int32 = cut1
    script.globals(base_local + 2).int32 = cut2
    script.globals(base_local + 3).int32 = cut3
    script.globals(base_local + 4).int32 = cut4
end

classicCutsMenu:button("应用分红"):event(menu.event.click, function()
    local c1 = get_selected_cut_value(combo_cut1)
    local c2 = get_selected_cut_value(combo_cut2)
    local c3 = get_selected_cut_value(combo_cut3)
    local c4 = get_selected_cut_value(combo_cut4)
    apply_cuts_from_values(c1, c2, c3, c4)
end)

local function apply_classic_preset(c1, c2, c3, c4)
    apply_cuts_from_values(c1, c2, c3, c4)

    local r1 = math.floor(c1 / 20 + 0.5) * 20
    local r2 = math.floor(c2 / 20 + 0.5) * 20
    local r3 = math.floor(c3 / 20 + 0.5) * 20
    local r4 = math.floor(c4 / 20 + 0.5) * 20
    
    combo_cut1.value = find_index(list_step_20, r1)
    combo_cut2.value = find_index(list_step_20, r2)
    combo_cut3.value = find_index(list_step_20, r3)
    combo_cut4.value = find_index(list_step_20, r4)
end

classicCutsHelper:button("全福银行最大收益"):event(menu.event.click, function()
    apply_classic_preset(1490, 1490, 1490, 1490)
end)

classicCutsHelper:button("监狱风云最大收益"):event(menu.event.click, function()
    apply_classic_preset(429, 429, 429, 429)
end)

classicCutsHelper:button("人道实验室最大收益"):event(menu.event.click, function()
    apply_classic_preset(317, 317, 317, 317)
end)

classicCutsHelper:button("首轮募资（崔佛）最大收益"):event(menu.event.click, function()
    apply_classic_preset(424, 424, 424, 424)
end)

classicCutsHelper:button("太平洋标准银行困难模式最大收益"):event(menu.event.click, function()
    apply_classic_preset(160, 160, 160, 160)
end)


classicCutsMenu:button("强制准备就绪"):event(menu.event.click, function()
    for i = 0, 3 do
        local globalIndex = 2658294 + 1 + (i * 468) + 270
        script.globals(globalIndex).int32 = 6
    end
end)

classicCutsMenu:toggle("1200万奖金（太平洋困难模式）"):event(menu.event.click, function(state)
    if state then
        account.stats("MPPLY_HEISTFLOWORDERPROGRESS").int32 = 268435455
        account.stats("MPPLY_AWD_HST_ORDER").bool = false
        
        account.stats("MPPLY_HEISTTEAMPROGRESSBITSET").int32 = 268435455
        account.stats("MPPLY_AWD_HST_SAME_TEAM").bool = false
        
        account.stats("MPPLY_HEISTNODEATHPROGREITSET").int32 = 268435455
        account.stats("MPPLY_AWD_HST_ULT_CHAL").bool = false
    else
        account.stats("MPPLY_HEISTFLOWORDERPROGRESS").int32 = 134217727
        account.stats("MPPLY_AWD_HST_ORDER").bool = true
        
        account.stats("MPPLY_HEISTTEAMPROGRESSBITSET").int32 = 134217727
        account.stats("MPPLY_AWD_HST_SAME_TEAM").bool = true
        
        account.stats("MPPLY_HEISTNODEATHPROGREITSET").int32 = 134217727
        account.stats("MPPLY_AWD_HST_ULT_CHAL").bool = true
    end
end)


cluckinMenu:button("跳过至终章"):event(menu.event.click, function()

    account.stats("MP0_SALV23_INST_PROG").int32 = 31
    account.stats("MP1_SALV23_INST_PROG").int32 = 31
    
    local other_stats = { "SALV23_GEN_BS", "SALV23_SCOPE_BS", "SALV23_FM_PROG" }
    for _, stat in ipairs(other_stats) do
        account.stats("MP0_" .. stat).int32 = -1
        account.stats("MP1_" .. stat).int32 = -1
    end
 
end)

cluckinMenu:button("移除冷却"):event(menu.event.click, function()
    account.stats("MP0_SALV23_CFR_COOLDOWN").int32 = -1
    account.stats("MP1_SALV23_CFR_COOLDOWN").int32 = -1
end)

cluckinMenu:button("重置进度"):event(menu.event.click, function()
    account.stats("MP0_SALV23_INST_PROG").int32 = 0
    account.stats("MP1_SALV23_INST_PROG").int32 = 0
end)


cluckinMenu:button("立即完成"):event(menu.event.click, function()
    local action_taken = false

    if script.running("circuitblockhack") then
        script.locals("circuitblockhack", 62).int32 = 2
        action_taken = true
    end

    if script.running("word_hack") then
        script.locals("word_hack", 106).int32 = 5
        action_taken = true
    end
if not action_taken and script.running("fm_mission_controller_2020") then
    local base = 56223 
    local cash_take_offset = 55173 
    script.locals("fm_mission_controller_2020", cash_take_offset).int32 = 4000000 
    script.locals("fm_mission_controller_2020", base + 1777).int32 = 999999
    script.locals("fm_mission_controller_2020", base + 1062).int32 = 5
    script.locals("fm_mission_controller_2020", 48794).int32 = script.locals("fm_mission_controller_2020", 48794).int32 | (1 << 7)
    local win_flags = (1 << 9) | (1 << 10) | (1 << 11) | (1 << 12) | (1 << 16)
    script.locals("fm_mission_controller_2020", base + 1).int32 = script.locals("fm_mission_controller_2020", base + 1).int32 | win_flags
    
    action_taken = true
end
end)


salvagePrepsMenu:button("完成任务准备"):event(menu.event.click, function()
    local stats = { "SALV23_GEN_BS", "SALV23_SCOPE_BS", "SALV23_FM_PROG", "SALV23_INST_PROG" }
    for _, statName in ipairs(stats) do
        account.stats("MP0_" .. statName).int32 = -1
        account.stats("MP1_" .. statName).int32 = -1
    end
end)

salvagePrepsMenu:button("重新加载任务面板"):event(menu.event.click, function()
    script.locals("vehrob_planning", 537).int32 = 2
end)

salvagePrepsMenu:button("重置任务准备"):event(menu.event.click, function()
    local stats = { "SALV23_GEN_BS", "SALV23_SCOPE_BS", "SALV23_FM_PROG", "SALV23_INST_PROG" }
    for _, statName in ipairs(stats) do
        account.stats("MP0_" .. statName).int32 = 0
        account.stats("MP1_" .. statName).int32 = 0
    end
end)


salvageToolsMenu:button("绕过无法启动错误"):event(menu.event.click, function()
    script.locals("vehrob_planning", 418).int32 = 1
    script.locals("tuner_planning", 408).int32 = 2
end)


local function set_bit(value, bit)
    return value | (1 << bit)
end

salvageToolsMenu:button("立即完成：货船"):event(menu.event.click, function()
    if script.running("fm_content_vehrob_cargo_ship") then
        local step1_loc = 7187 + 1
        local val = script.locals("fm_content_vehrob_cargo_ship", step1_loc).int32
        script.locals("fm_content_vehrob_cargo_ship", step1_loc).int32 = set_bit(val, 11)
        script.locals("fm_content_vehrob_cargo_ship", 8581).int32 = 2
    end
end)

salvageToolsMenu:button("立即完成：帮派分子"):event(menu.event.click, function()
    if script.running("fm_content_vehrob_police") then
        local step1_loc = 9013 + 1
        local val = script.locals("fm_content_vehrob_police", step1_loc).int32
        script.locals("fm_content_vehrob_police", step1_loc).int32 = set_bit(val, 11)
        script.locals("fm_content_vehrob_police", 10451).int32 = 2
    end
end)

salvageToolsMenu:button("立即完成：杜根"):event(menu.event.click, function()
    if script.running("fm_content_vehrob_arena") then
        local step1_loc = 7914 + 1
        local val = script.locals("fm_content_vehrob_arena", step1_loc).int32
        script.locals("fm_content_vehrob_arena", step1_loc).int32 = set_bit(val, 11)
        script.locals("fm_content_vehrob_arena", 9348).int32 = 2
    end
end)

salvageToolsMenu:button("立即完成：领奖台"):event(menu.event.click, function()
    if script.running("fm_content_vehrob_casino_prize") then
        local step1_loc = 9194 + 1
        local val = script.locals("fm_content_vehrob_casino_prize", step1_loc).int32
        script.locals("fm_content_vehrob_casino_prize", step1_loc).int32 = set_bit(val, 11)
        script.locals("fm_content_vehrob_casino_prize", 10588).int32 = 2
    end
end)

salvageToolsMenu:button("立即完成：麦克托尼"):event(menu.event.click, function()
    if script.running("fm_content_vehrob_submarine") then
        local step1_loc = 6220 + 1
        local val = script.locals("fm_content_vehrob_submarine", step1_loc).int32
        script.locals("fm_content_vehrob_submarine", step1_loc).int32 = set_bit(val, 11)
        script.locals("fm_content_vehrob_submarine", 7517).int32 = 2
    end
end)

local selectedContractIndex = 3 

local function selectContract(index, name)
    selectedContractIndex = index
end

contractsMenu:button("无"):event(menu.event.click, function() selectContract(3, "无") end)
contractsMenu:button("夜总会"):event(menu.event.click, function() selectContract(4, "夜总会") end)
contractsMenu:button("码头"):event(menu.event.click, function() selectContract(12, "码头") end)
contractsMenu:button("夜生活泄露"):event(menu.event.click, function() selectContract(28, "夜生活泄露") end)
contractsMenu:button("乡村俱乐部"):event(menu.event.click, function() selectContract(60, "乡村俱乐部") end)
contractsMenu:button("贵宾名单"):event(menu.event.click, function() selectContract(123, "贵宾名单") end)
contractsMenu:button("上流社会泄露"):event(menu.event.click, function() selectContract(254, "上流社会泄露") end)
contractsMenu:button("戴维斯"):event(menu.event.click, function() selectContract(508, "戴维斯") end)
contractsMenu:button("巴勒帮"):event(menu.event.click, function() selectContract(1020, "巴勒帮") end)
contractsMenu:button("南中央泄露"):event(menu.event.click, function() selectContract(2044, "南中央泄露") end)
contractsMenu:button("录音室时间"):event(menu.event.click, function() selectContract(2045, "录音室时间") end)
contractsMenu:button("别惹 W. Dre"):event(menu.event.click, function() selectContract(4095, "别惹 W. Dre") end)

agencyPrepsMenu:button("完成准备并应用合同"):event(menu.event.click, function()

    local activeChar = script.globals(1574927).int32
    if activeChar ~= 0 and activeChar ~= 1 then activeChar = 0 end 
    local prefix = "MP" .. activeChar .. "_"

    account.stats(prefix .. "FIXER_STORY_BS").int32 = selectedContractIndex

    local strand = -1
    if selectedContractIndex < 18 then
        strand = 0
    elseif selectedContractIndex < 128 then
        strand = 1
    elseif selectedContractIndex < 2044 then
        strand = 2
    end

    account.stats(prefix .. "FIXER_STORY_STRAND").int32 = strand
    account.stats(prefix .. "FIXER_GENERAL_BS").int32 = -1
    account.stats(prefix .. "FIXER_COMPLETED_BS").int32 = -1
end)


agencyToolsMenu:button("设置最大收益（任务开始后使用）"):event(menu.event.click, function()
    script.globals(262145 + 31249).int32 = 2500000
end)

agencyToolsMenu:button("移除事务所冷却"):event(menu.event.click, function()
    local charIndex = script.globals(1574927).int32 or 0
    if charIndex ~= 1 then charIndex = 0 end 
    local prefix = "MP" .. tostring(charIndex) .. "_"

    account.stats(prefix .. "FIXER_STORY_COOLDOWN_POSIX").int32 = 0
    account.stats(prefix .. "FIXER_SECURITY_CONTRACT_COOLDOWN_TIME").int32 = 0
    account.stats(prefix .. "REQUEST_FRANKLIN_PAYPHONE_HIT_COOLDOWN").int32 = 0

end)

agencyToolsMenu:button("即时笔记本电脑破解"):event(menu.event.click, function()
    if script.running("fm_mission_controller") then
        script.locals("fm_mission_controller", 171).int32 = 0
        script.locals("fm_mission_controller", 168).int32 = 0
        script.locals("fm_mission_controller", 183).int32 = 7
    end
end)


agencyToolsMenu:button("立即完成事务所"):event(menu.event.click, function()
        script.locals("fm_mission_controller_2020", 56223 + 1).int32 = 51338752
        script.locals("fm_mission_controller_2020", 56223 + 1776 + 1).int32 = 50
end)

local selectedContract = -1 

local autoShopContracts = {
    { name = "无", index = -1 },
    { name = "联合储蓄", index = 0 },
    { name = "超级美钞交易", index = 1 },
    { name = "银行合同", index = 2 },
    { name = "ECU任务", index = 3 },
    { name = "监狱合同", index = 4 },
    { name = "事务所交易", index = 5 },
    { name = "失落帮合同", index = 6 },
    { name = "数据合同", index = 7 }
}

local function apply_and_complete_auto_shop()
    if selectedContract < 0 then
        return
    end

    local activeChar = script.globals(1574927).int32
    if activeChar ~= 0 and activeChar ~= 1 then activeChar = 0 end 
    local prefix = "MP" .. activeChar .. "_"

    account.stats(prefix .. "TUNER_CURRENT").int32 = selectedContract

    local gen_bs_value = (selectedContract == 1) and 4351 or 12543
    account.stats(prefix .. "TUNER_GEN_BS").int32 = gen_bs_value

    script.locals("tuner_planning", 408).int32 = 2
end


for _, contract in ipairs(autoShopContracts) do
    autoshopcontractsmenu:button(contract.name):event(menu.event.click, function()
        selectedContract = contract.index
    end)
end

autoshopPrepsMenu:button("跳过准备并应用合同"):event(menu.event.click, function()
    apply_and_complete_auto_shop()
end)

autoshopPrepsMenu:button("重绘面板"):event(menu.event.click, function()
    script.locals("tuner_planning", 408).int32 = 2
end)

autoshopToolMenu:button("立即完成改车铺"):event(menu.event.click, function()
    if script.force_host("fm_mission_controller_2020") then
        util.yield(1000)
        script.locals("fm_mission_controller_2020", 56223).int32 = 51338977
        script.locals("fm_mission_controller_2020", 58000).int32 = 101
    end
end)

autoshopToolMenu:button("即时伏特实验室"):event(menu.event.click, function()
    if script.running("fm_mission_controller_2020") then
        local target = script.locals("fm_mission_controller_2020", 1749).int32
        script.locals("fm_mission_controller_2020", 1748).int32 = target
        script.locals("fm_mission_controller_2020", 1750).int32 = 3
    end
end)

local payout = 1000000


local default_idx_autoshop = find_index(list_autoshop_payout, 1000000)
local autoshop_combo = autoshopmoneyMenu:combo_int("收益金额", list_autoshop_payout, menu.type.scroll)

autoshop_combo.value = default_idx_autoshop 

autoshop_combo:event(menu.event.click, function(combo)
    payout = list_autoshop_payout[combo.value][2]
end)

autoshopmoneyMenu:button("最大收益（不生效）"):event(menu.event.click, function()
    payout = 2200000
end)


autoshopmoneyMenu:button("应用收益（任务开始后使用）"):event(menu.event.click, function()

    script.tunables("TUNER_ROBBERY_LEADER_CASH_REWARD0").int32 = payout
    script.tunables("TUNER_ROBBERY_LEADER_CASH_REWARD1").int32 = payout
    script.tunables("TUNER_ROBBERY_LEADER_CASH_REWARD2").int32 = payout
    script.tunables("TUNER_ROBBERY_LEADER_CASH_REWARD3").int32 = payout
    script.tunables("TUNER_ROBBERY_LEADER_CASH_REWARD4").int32 = payout
    script.tunables("TUNER_ROBBERY_LEADER_CASH_REWARD5").int32 = payout
    script.tunables("TUNER_ROBBERY_LEADER_CASH_REWARD6").int32 = payout
    script.tunables("TUNER_ROBBERY_LEADER_CASH_REWARD7").int32 = payout
    script.locals("tuner_planning", 408).int32 = 2
end)

autoshopmoneyMenu:button("最大收益不适用于联合储蓄"):event(menu.event.click, function() end)


cayoMenu:button("最高收益为 2,550,000$"):event(menu.event.click, function() end)

local function MPX_Cayo()
    local charIndex = script.globals(1574927).int32
    return "MP" .. tostring(charIndex) .. "_"
end

local function unlockAllCayoPOI()

    account.stats("MP0_H4CNF_BS_GEN").int32 = -1
    account.stats("MP0_H4CNF_BS_ENTR").int32 = 63
    account.stats("MP0_H4CNF_BS_ABIL").int32 = 63
    account.stats("MP0_H4CNF_APPROACH").int32 = -1
    account.stats("MP0_H4_PLAYTHROUGH_STATUS").int32 = 10
    script.locals("heist_island_planning", 1570).int32 = 2

    account.stats("MP1_H4CNF_BS_GEN").int32 = -1
    account.stats("MP1_H4CNF_BS_ENTR").int32 = 63
    account.stats("MP1_H4CNF_BS_ABIL").int32 = 63
    account.stats("MP1_H4CNF_APPROACH").int32 = -1
    account.stats("MP1_H4_PLAYTHROUGH_STATUS").int32 = 10
    script.locals("heist_island_planning", 1570).int32 = 2
end

cayoprepsMenu:button("解锁所有佩里科岛兴趣点"):event(menu.event.click, unlockAllCayoPOI)

local selectedDifficulty = 126823
local difficulties = {
    { name = "普通", index = 126823 },
    { name = "困难", index = 131055 }
}
for _, diff in ipairs(difficulties) do
    difficultyMenu:button(diff.name):event(menu.event.click, function()
        selectedDifficulty = diff.index
    end)
end

local selectedApproach = 65535
local approaches = {
    { name = "科萨卡", index = 65283 }, { name = "阿尔科诺斯特", index = 65413 },
    { name = "维卢姆", index = 65289 }, { name = "隐形歼灭者", index = 65425 },
    { name = "巡逻艇", index = 65313 }, { name = "长鳍", index = 65345 },
    { name = "全部方式", index = 65535 }
}
for _, approach in ipairs(approaches) do
    approachMenu:button(approach.name):event(menu.event.click, function()
        selectedApproach = approach.index
    end)
end

local selectedLoadout = 1
local loadouts = {
    { name = "侵略者", index = 1 }, { name = "阴谋家", index = 2 },
    { name = "神枪手", index = 3 }, { name = "破坏者", index = 4 },
    { name = "射手", index = 5 }
}
for _, loadout in ipairs(loadouts) do
    loadoutMenu:button(loadout.name):event(menu.event.click, function()
        selectedLoadout = loadout.index
    end)
end

local selectedTarget = 5
local targets = {
    { name = "龙舌兰", index = 0 }, { name = "红宝石项链", index = 1 },
    { name = "不记名债券", index = 2 }, { name = "粉钻", index = 3 },
    { name = "马达佐档案", index = 4 }, { name = "黑豹雕像", index = 5 }
}
for _, target in ipairs(targets) do
    targetMenu:button(target.name):event(menu.event.click, function()
        selectedTarget = target.index
    end)
end

local selectedCompoundTarget = "GOLD"
local selectedIslandTarget = "GOLD"

local secondaryTargets = {
    { name = "无", index = "NONE" }, { name = "现金", index = "CASH" },
    { name = "大麻", index = "WEED" }, { name = "可卡因", index = "COKE" },
    { name = "黄金", index = "GOLD" }
}

for _, target in ipairs(secondaryTargets) do
    secondaryMenu:button(target.name):event(menu.event.click, function()
        selectedCompoundTarget = target.index
    end)
end

for _, target in ipairs(secondaryTargets) do
    islandTargetMenu:button(target.name):event(menu.event.click, function()
        selectedIslandTarget = target.index
    end)
end

local selectedCompoundAmount = 255
local compoundAmounts = {
    { name = "空", index = 0 }, { name = "满", index = 255 }, { name = "1", index = 128 },
    { name = "2", index = 64 }, { name = "3", index = 196 }, { name = "4", index = 204 },
    { name = "5", index = 220 }, { name = "6", index = 252 }, { name = "7", index = 253 }
}
for _, amount in ipairs(compoundAmounts) do
    compoundAmountMenu:button(amount.name):event(menu.event.click, function()
        selectedCompoundAmount = amount.index
    end)
end

local selectedIslandAmount = 16777215
local islandAmounts = {
    { name = "空", index = 0 }, { name = "满", index = 16777215 }, { name = "1", index = 8388608 },
    { name = "2", index = 12582912 }, { name = "3", index = 12845056 }, { name = "4", index = 12976128 },
    { name = "5", index = 13500416 }, { name = "6", index = 14548992 }, { name = "7", index = 16646144 },
    { name = "8", index = 16711680 }, { name = "9", index = 16744448 }, { name = "10", index = 16760832 },
    { name = "11", index = 16769024 }, { name = "12", index = 16769536 }, { name = "13", index = 16770560 },
    { name = "14", index = 16770816 }, { name = "15", index = 16770880 }, { name = "16", index = 16771008 },
    { name = "17", index = 16773056 }, { name = "18", index = 16777152 }, { name = "19", index = 16777184 },
    { name = "20", index = 16777200 }, { name = "21", index = 16777202 }, { name = "22", index = 16777203 },
    { name = "23", index = 16777211 }
}
for _, amount in ipairs(islandAmounts) do
    islandAmountMenu:button(amount.name):event(menu.event.click, function()
        selectedIslandAmount = amount.index
    end)
end

local selectedArtsAmount = 127
local artsAmounts = {
    { name = "空", index = 0 }, { name = "满", index = 127 }, { name = "1", index = 64 },
    { name = "2", index = 96 }, { name = "3", index = 112 }, { name = "4", index = 120 },
    { name = "5", index = 122 }, { name = "6", index = 126 }
}
for _, amount in ipairs(artsAmounts) do
    artsAmountMenu:button(amount.name):event(menu.event.click, function()
        selectedArtsAmount = amount.index
    end)
end

local cashValue = 83250
local weedValue = 135000
local cokeValue = 202500
local goldValue = 333333
local artsValue = 180000

local default_cayo_cash = find_index(list_cayo_cash_val, cashValue)
LootOptionsMenu:combo_int("现金价值", list_cayo_cash_val, menu.type.scroll)
    :event(menu.event.click, function(combo) cashValue = list_cayo_cash_val[combo.value][2] end).value = default_cayo_cash

local default_cayo_weed = find_index(list_cayo_weed_val, weedValue)
LootOptionsMenu:combo_int("大麻价值", list_cayo_weed_val, menu.type.scroll)
    :event(menu.event.click, function(combo) weedValue = list_cayo_weed_val[combo.value][2] end).value = default_cayo_weed

local default_cayo_coke = find_index(list_cayo_coke_val, cokeValue)
LootOptionsMenu:combo_int("可卡因价值", list_cayo_coke_val, menu.type.scroll)
    :event(menu.event.click, function(combo) cokeValue = list_cayo_coke_val[combo.value][2] end).value = default_cayo_coke

local default_cayo_gold = find_index(list_cayo_gold_val, goldValue)
LootOptionsMenu:combo_int("黄金价值", list_cayo_gold_val, menu.type.scroll)
    :event(menu.event.click, function(combo) goldValue = list_cayo_gold_val[combo.value][2] end).value = default_cayo_gold

local default_cayo_arts = find_index(list_cayo_arts_val, artsValue)
LootOptionsMenu:combo_int("艺术品价值", list_cayo_arts_val, menu.type.scroll)
    :event(menu.event.click, function(combo) artsValue = list_cayo_arts_val[combo.value][2] end).value = default_cayo_arts


local function applyPreps(
    selectedDifficulty, selectedApproach, selectedLoadout,
    selectedTarget,
    selectedCompoundTarget, selectedCompoundAmount, selectedArtsAmount,
    selectedIslandTarget, selectedIslandAmount,
    cashValue, weedValue, cokeValue, goldValue, artsValue)

    local prefix = MPX_Cayo()

    account.stats(prefix .. "H4_PROGRESS").int32 = selectedDifficulty
    account.stats(prefix .. "H4_MISSIONS").int32 = selectedApproach
    account.stats(prefix .. "H4CNF_WEAPONS").int32 = selectedLoadout
    account.stats(prefix .. "H4CNF_TARGET").int32 = selectedTarget

    local lootTypes = { "CASH", "WEED", "COKE", "GOLD" }
    for _, loot in ipairs(lootTypes) do
        local value = (selectedCompoundTarget == loot) and selectedCompoundAmount or 0
        account.stats(prefix .. "H4LOOT_" .. loot .. "_C").int32 = value
        account.stats(prefix .. "H4LOOT_" .. loot .. "_C_SCOPED").int32 = value
    end

    for _, loot in ipairs(lootTypes) do
        local value = (selectedIslandTarget == loot) and selectedIslandAmount or 0
        account.stats(prefix .. "H4LOOT_" .. loot .. "_I").int32 = value
        account.stats(prefix .. "H4LOOT_" .. loot .. "_I_SCOPED").int32 = value
    end

    account.stats(prefix .. "H4LOOT_PAINT").int32 = selectedArtsAmount or 0
    account.stats(prefix .. "H4LOOT_PAINT_SCOPED").int32 = selectedArtsAmount or 0

    local lootValues = { CASH = cashValue, WEED = weedValue, COKE = cokeValue, GOLD = goldValue }
    for loot, value in pairs(lootValues) do
        local hasLoot = (selectedCompoundTarget == loot or selectedIslandTarget == loot)
        account.stats(prefix .. "H4LOOT_" .. loot .. "_V").int32 = hasLoot and value or 0
    end

    account.stats(prefix .. "H4LOOT_PAINT_V").int32 = selectedArtsAmount > 0 and artsValue or 0

    account.stats(prefix .. "H4CNF_UNIFORM").int32 = -1
    account.stats(prefix .. "H4CNF_GRAPPEL").int32 = -1
    account.stats(prefix .. "H4CNF_TROJAN").int32 = 5
    account.stats(prefix .. "H4CNF_WEP_DISRP").int32 = 3
    account.stats(prefix .. "H4CNF_ARM_DISRP").int32 = 3
    account.stats(prefix .. "H4CNF_HEL_DISRP").int32 = 3

    script.locals("heist_island_planning", 1570).int32 = 2
end

cayoprepsMenu:button("应用准备"):event(menu.event.click, function()
    applyPreps(
        selectedDifficulty,
        selectedApproach,
        selectedLoadout,
        selectedTarget,
        selectedCompoundTarget,
        selectedCompoundAmount,
        selectedArtsAmount,
        selectedIslandTarget,
        selectedIslandAmount,
        cashValue,
        weedValue,
        cokeValue,
        goldValue,
        artsValue
    )
end)


local function reset_cayo_preps()
    local prefix = MPX_Cayo()

    account.stats(prefix .. "H4_PROGRESS").int32 = 0
    account.stats(prefix .. "H4_MISSIONS").int32 = 0
    account.stats(prefix .. "H4CNF_APPROACH").int32 = 0
    account.stats(prefix .. "H4CNF_TARGET").int32 = -1
    account.stats(prefix .. "H4CNF_BS_GEN").int32 = 0
    account.stats(prefix .. "H4CNF_BS_ENTR").int32 = 0
    account.stats(prefix .. "H4CNF_BS_ABIL").int32 = 0
    account.stats(prefix .. "H4_PLAYTHROUGH_STATUS").int32 = 0

    script.locals("heist_island_planning", 1570).int32 = 2
end


cayoprepsMenu:button("重置准备"):event(menu.event.click, function()
    reset_cayo_preps()
end)

cayotoolsMenu:button("重新加载规划屏幕"):event(menu.event.click, function()
    script.locals("heist_island_planning", 1570).int32 = 2
end)



cayotoolsMenu:button("即时伏特实验室破解"):event(menu.event.click, function()
    if script.running("fm_content_island_heist") then
        local target = script.locals("fm_content_island_heist", 793).int32
        script.locals("fm_content_island_heist", 794).int32 = target
        script.locals("fm_content_island_heist", 795).int32 = 3
        script.locals("fm_content_island_heist", 10166 + 24).int32 = 7
    end
    
    if script.running("fm_mission_controller_2020") then
        local target = script.locals("fm_mission_controller_2020", 1771).int32
        script.locals("fm_mission_controller_2020", 1770).int32 = target
        script.locals("fm_mission_controller_2020", 1772).int32 = 3
    end
end)

cayotoolsMenu:button("即时密码破解"):event(menu.event.click, function()

        script.locals("fm_mission_controller_2020", 26486).int32 = 5
end)

cayotoolsMenu:button("绕过等离子切割机"):event(menu.event.click, function()
    script.locals("fm_mission_controller_2020", 32592).float = 100.0
end)

cayotoolsMenu:button("绕过排水管道切割"):event(menu.event.click, function()
    script.locals("fm_mission_controller_2020", 31349).int32 = 6
end)

cayotoolsMenu:button("移除单人冷却"):event(menu.event.click, function()
    local prefix = MPX_Cayo()
    account.stats(prefix .. "H4_TARGET_POSIX").int32 = 1659643454
    account.stats(prefix .. "H4_COOLDOWN").int32 = 0
    account.stats(prefix .. "H4_COOLDOWN_HARD").int32 = 0
end)

cayotoolsMenu:button("移除团队冷却"):event(menu.event.click, function()
    local prefix = MPX_Cayo()
    account.stats(prefix .. "H4_TARGET_POSIX").int32 = 1659429119
    account.stats(prefix .. "H4_COOLDOWN").int32 = 0
    account.stats(prefix .. "H4_COOLDOWN_HARD").int32 = 0
end)

cayotoolsMenu:button("立即完成佩里科岛"):event(menu.event.click, function()
    if script.force_host("fm_mission_controller_2020") then
        util.yield(1000)
        script.locals("fm_mission_controller_2020", 56223).int32 = 9
        script.locals("fm_mission_controller_2020", 58000).int32 = 50
    end
end)

local cayo_cuts_base = 1980035 + 831 + 56
local default_idx_0_step25_cayo = find_index(list_step_25, 0)

local cayo_combo_cut1 = cayoCutsMenu:combo_int("主机分红 %", list_step_25, menu.type.scroll)
cayo_combo_cut1.value = default_idx_0_step25_cayo

local cayo_combo_cut2 = cayoCutsMenu:combo_int("玩家 2 分红 %", list_step_25, menu.type.scroll)
cayo_combo_cut2.value = default_idx_0_step25_cayo

local cayo_combo_cut3 = cayoCutsMenu:combo_int("玩家 3 分红 %", list_step_25, menu.type.scroll)
cayo_combo_cut3.value = default_idx_0_step25_cayo

local cayo_combo_cut4 = cayoCutsMenu:combo_int("玩家 4 分红 %", list_step_25, menu.type.scroll)
cayo_combo_cut4.value = default_idx_0_step25_cayo

local function get_cayo_cut_value(combo_obj)
    if combo_obj.value > #list_step_25 then return 100 end
    return list_step_25[combo_obj.value][2]
end

local function apply_cayo_cuts(cut1, cut2, cut3, cut4)
    script.globals(cayo_cuts_base + 1).int32 = cut1
    script.globals(cayo_cuts_base + 2).int32 = cut2
    script.globals(cayo_cuts_base + 3).int32 = cut3
    script.globals(cayo_cuts_base + 4).int32 = cut4
end

cayoCutsMenu:button("应用分红"):event(menu.event.click, function()
    local c1 = get_cayo_cut_value(cayo_combo_cut1)
    local c2 = get_cayo_cut_value(cayo_combo_cut2)
    local c3 = get_cayo_cut_value(cayo_combo_cut3)
    local c4 = get_cayo_cut_value(cayo_combo_cut4)
    apply_cayo_cuts(c1, c2, c3, c4)
end)

cayoCutsMenu:button("强制所有玩家准备就绪"):event(menu.event.click, function()
    local base = 1981147
    for i = 0, 3 do
        script.globals(base + 1 + (i * 27) + 8).int32 = 1
    end
end)

payphoneMenu:button("（电话暗杀）设置冷却时间为 0"):event(menu.event.click, function()
    script.globals(262145 + 31283).int32 = 0
end)

payphoneMenu:button("（安保合同）设置冷却时间为 0"):event(menu.event.click, function()
    script.globals(262145 + 31203).int32 = 0
end)


payphoneMenu:button("立即完成（资产保护）"):event(menu.event.click, function()
    if script.running("fm_content_security_contract") then
        script.locals("fm_content_security_contract", 1858).int32 = 0
    end
end)


local GB_BOSS_WORK = 1950714 


local sightseer_menu = vipWorkMenu:submenu("观光客选项")
local fortified_menu = vipWorkMenu:submenu("堡垒选项")



sightseer_menu:button("重置观光客冷却时间"):event(menu.event.click, function()
    script.globals(GB_BOSS_WORK + 12960).int32 = 0
end)

sightseer_menu:button("操控收益"):event(menu.event.click, function()
    script.globals(GB_BOSS_WORK + 12963).int32 = 22500
    script.globals(GB_BOSS_WORK + 12968).float = 2.0
    script.globals(GB_BOSS_WORK + 12964).int32 = 10000
    script.globals(GB_BOSS_WORK + 12969).float = 2.5
end)

sightseer_menu:button("立即完成"):event(menu.event.click, function()
    script.globals(GB_BOSS_WORK + 12961).int32 = 0
end)



fortified_menu:button("重置堡垒冷却时间"):event(menu.event.click, function()
    script.globals(GB_BOSS_WORK + 19229).int32 = 0
end)

fortified_menu:button("立即开始堡垒"):event(menu.event.click, function()
    script.globals(GB_BOSS_WORK + 19226).int32 = 20000
end)

local fortified_timer_default = 600
local default_idx_fortified = find_index(list_fortified_timer, fortified_timer_default)
local fortified_timer_combo = fortified_menu:combo_int("堡垒计时器（秒）", list_fortified_timer, menu.type.scroll)

fortified_timer_combo.value = default_idx_fortified

fortified_menu:button("应用堡垒计时器"):event(menu.event.click, function()
    local selected_time_seconds = list_fortified_timer[fortified_timer_combo.value][2]
    script.globals(GB_BOSS_WORK + 19227).int32 = selected_time_seconds * 1000 
end)

fortified_menu:button("堡垒最大现金（仅本地）"):event(menu.event.click, function()
    script.globals(GB_BOSS_WORK + 19230).int32 = 30000
end)